﻿using OnlineLearningSystem.IRepository;
using OnlineLearningSystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineLearningSystem.Repository
{
    public class CourseRepository : ICourseRepository
    {
        private readonly AppDbContext _context;

        public CourseRepository(AppDbContext context)
        {
            _context = context;
        }
        public void Create(Course entity)
        {
            _context.Courses.Add(entity);
            _context.SaveChanges();
        }

        public void Delete(Course course)
        {
            _context.Courses.Remove(course);
            _context.SaveChanges();
        }

        public Course Get(Func<Course, bool> wherelambda)
        {
            return _context.Courses.Where(wherelambda).FirstOrDefault(); 
        }

        public List<Course> GetAll()
        {
            return _context.Courses.ToList();
        }

        public void Update(Course course)
        {
            _context.Courses.Update(course);
            _context.SaveChanges();
        }
    }
}
